﻿using System;
using System.Collections.Generic;
using System.Text;
using MySoft.Data.Logger;
using ComLib.Debug;

namespace MySoft.Data
{
    public static class DataAccess
    {
        #region - 变量 -

        /// <summary>
        /// 通过配置节来实例化DbSession
        /// </summary>
        public static readonly DbSession DefaultSession = new DbSession("conectionstring");

        /// <summary>
        /// 通过自定义类来实例化DbSession
        /// </summary>
        public static readonly MyDbSession MyDbSession = new MyDbSession();

        #endregion
    }

    /// <summary>
    /// DataExample会话类
    /// </summary>
    public class MyDbSession : DbSession, IExecuteCommand
    {
        #region - 构造函数 -

        public MyDbSession()
            : base("conectionstring")
        {
            this.RegisterLogger(this);
        }

        #endregion

        //日志接口
        #region IExecuteCommand实现
        public void BeginExecute(System.Data.Common.DbCommand command)
        {
            DebugView.PrintDebug("=====[MySoft.Data]=====>","[BeginExecute]:" + DataHelper.GetCommandLog(command));
        }

        public void EndExecute(System.Data.Common.DbCommand command, ReturnValue retValue, long elapsedTime)
        {
            DebugView.PrintDebug("=====[MySoft.Data]=====>", "[EndExecute]:" + DataHelper.GetCommandLog(command) + "[RetValue]:" + retValue.Count + "[ElapsedTime]:" + elapsedTime);
        }
        #endregion
    }
}
